//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package objects;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.TreeMap;

public class ProductionQueue {
    private List<String> queue = new ArrayList();

    public ProductionQueue() {
    }

    public void init(LinkedHashMap<String, Integer> planning) {
        this.queue.clear();
        TreeMap sortedPlanning = new TreeMap(new StringKeyIntValueComparator(planning));
        sortedPlanning.putAll(planning);
        LinkedHashMap val = new LinkedHashMap();
        Integer devider = Integer.valueOf(0);
        if(planning.size() > 0) {
            devider = (Integer)sortedPlanning.values().toArray()[0];
        }

        if(devider == null || devider.intValue() == 0) {
            devider = Integer.valueOf(1);
        }

        String zeroes;
        int v;
        for(Iterator key = planning.keySet().iterator(); key.hasNext(); val.put(zeroes, Integer.valueOf(v))) {
            zeroes = (String)key.next();
            Integer num = (Integer)planning.get(zeroes);
            v = num.intValue() / devider.intValue();
            int add = num.intValue() % devider.intValue();
            if(add >= devider.intValue() / 2) {
                ++v;
            }
        }

        int var10 = 0;

        while(var10 < val.size()) {
            Iterator var12 = val.keySet().iterator();

            while(var12.hasNext()) {
                String var11 = (String)var12.next();
                Integer var13 = (Integer)val.get(var11);
                if(var13.intValue() > 0) {
                    this.queue.add(var11);
                    val.put(var11, Integer.valueOf(var13.intValue() - 1));
                } else {
                    ++var10;
                }
            }
        }

    }

    public String head() {
        return this.queue.size() > 0?(String)this.queue.get(0):null;
    }

    public String shiftHead() {
        String a = (String)this.queue.remove(0);
        this.queue.add(a);
        return a;
    }

    public String queueToString() {
        return this.queue.toString();
    }
}
